//
//  DYJingdianTuijianSubCell.swift
//  SheYangBigData
//
//  Created by 宋海胜 on 2021/1/4.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit
import YYText

class DYJingdianTuijianSubCell: SYBaseCollectionViewCell {
    
    
    var bgView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = .white
        v.layer.cornerRadius = 5
        
        v.layer.shadowColor = UIColor(hex: 0xB3B3B3).cgColor
        v.layer.shadowOpacity = 0.5//阴影透明度
        v.layer.shadowOffset = CGSize.zero///阴影偏移量,四周
        v.layer.shadowRadius = 2.5//阴影半径  shadowPathWidth：阴影宽度
        return v
    }()
    
    let wenLb: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x1E1E1E)
        v.font = 15.autoFontSize()
        
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.layer.cornerRadius = 6
        return v
    }()
    
    let priceLb: YYLabel = {
        let v:YYLabel = YYLabel()
        v.textColor = UIColor(hex: 0xF55035)
        v.font = 15.autoFontSize()
        
        return v
    }()
    

    public func configureView(_ model: DYScenicSpotListModel) {
        wenLb.text = model.name
        let showStr = "¥\(model.rates ?? "") 起"
        let attString = NSMutableAttributedString(string: showStr)
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 0, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: 0, length: 1))
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 1, length: showStr.count-2))
        attString.yy_setFont(14.autoFontSize(), range: NSRange(location: 1, length: showStr.count-2))
        attString.yy_setColor(UIColor(hex: 0xAFAFAF), range: NSRange(location: showStr.count-1, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: showStr.count-1, length: 1))
        priceLb.attributedText = attString
        pic.sy_setWithUrl(model.imgUrl)
    }
    
    public func configureMSView(_ model: DYTourRestaurantListModel) {
        wenLb.text = model.name
        let showStr = "¥\(model.cost) 人均"
        let attString = NSMutableAttributedString(string: showStr)
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 0, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: 0, length: 1))
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 1, length: showStr.count-3))
        attString.yy_setFont(14.autoFontSize(), range: NSRange(location: 1, length: showStr.count-3))
        attString.yy_setColor(UIColor(hex: 0xAFAFAF), range: NSRange(location: showStr.count-2, length: 2))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: showStr.count-2, length: 2))
        priceLb.attributedText = attString
        let imgUrls = model.imgUrl?.components(separatedBy: ",")
        pic.sy_setWithUrl(imgUrls?.first)
    }
    
    public func configureZSView(_ model: DYZSTourHotelListModel) {
        wenLb.text = model.name
        let showStr = "¥\(model.rates ?? "") 起"
        let attString = NSMutableAttributedString(string: showStr)
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 0, length: 1))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: 0, length: 1))
        attString.yy_setColor(UIColor(hex: 0xF55035), range: NSRange(location: 1, length: showStr.count-3))
        attString.yy_setFont(14.autoFontSize(), range: NSRange(location: 1, length: showStr.count-3))
        attString.yy_setColor(UIColor(hex: 0xAFAFAF), range: NSRange(location: showStr.count-2, length: 2))
        attString.yy_setFont(10.autoFontSize(), range: NSRange(location: showStr.count-2, length: 2))
        priceLb.attributedText = attString
        let imgUrls = model.imgUrl?.components(separatedBy: ",")
        pic.sy_setWithUrl(imgUrls?.first)
    }
    
    
    
    override func initViews() {
        
        addSubview(bgView)
        bgView.addSubview(wenLb)
        bgView.addSubview(pic)
        bgView.addSubview(priceLb)
        bgView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(2.5)
            make.right.equalToSuperview().offset(-2.5)
            make.top.bottom.equalToSuperview()
        }
        wenLb.snp.makeConstraints { (make) in
            make.top.equalTo(pic.snp.bottom).offset(8.5.autoWidth())
            make.left.equalTo(pic.snp.left).offset(7.5.autoWidth())
            make.right.equalTo(pic.snp.right).offset(-7.5.autoWidth())
            make.height.equalTo(14.5.autoWidth())
        }
        pic.snp.makeConstraints { (make) in
            make.top.equalToSuperview()
            make.left.right.equalToSuperview()
            make.width.equalTo(170.0.autoWidth())
            make.height.equalTo(123.0.autoWidth())
        }
        priceLb.snp.makeConstraints { (make) in
            make.top.equalTo(wenLb.snp.bottom).offset(7.5.autoWidth())
            make.left.equalTo(wenLb)
            make.height.equalTo(11.0.autoWidth())
            make.bottom.equalToSuperview().offset(-9.0.autoWidth())
        }
    }
}

